//this lib uses jsutil lib
function SwitchScript(id){
	
	var m_url = '';
	
	(function checkRequiredLib(){
		if(typeof jsutil !== 'function'){
			alert("switchScript require jsutil lib");
			return false;
		}
		if(typeof ($.ajat) !== 'function'){
			alert("switchScript require jquery and ajat lib");
		}
	}());
	
	function swit(url, callback){
		var datatype = "html";
		if(jsutil().endsWith(url, "js")){
			datatype = "script"; 
		}
//		$.get(url,function(script,status){
//			debug("swit success");
//		});
		
		$.ajat({
			url: url,
			type: 'get',
			dataType:datatype,
			success: function(script, status){
				var script = script.replace(/<script.*>/gi,'').replace(/<\/script>/gi,'');
				debug("script="+script);
				$('#'+id).remove();
				var $script = $("<script/>",{id:id});
				$("body").append($script);
				$script.html(script);
				
				m_url = url;
				
				if (typeof callback === 'function'){
					callback();
				}
			}
		});
	}
	
	function isUrlLoaded(url){
		return (m_url === url?true:false);
	}
	
	return {
		swit: swit,
		isUrlLoaded: isUrlLoaded
	}
	
}
